from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-29 14:02:10.257563
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 29, May, 2022
Time: 14:02:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4548
Nobs: 671.000 HQIC: -49.8254
Log likelihood: 8316.02 FPE: 1.81722e-22
AIC: -50.0596 Det(Omega_mle): 1.59069e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.305866 0.059610 5.131 0.000
L1.Burgenland 0.107295 0.038563 2.782 0.005
L1.Kärnten -0.109944 0.020284 -5.420 0.000
L1.Niederösterreich 0.196155 0.080243 2.445 0.015
L1.Oberösterreich 0.127513 0.079377 1.606 0.108
L1.Salzburg 0.255676 0.041033 6.231 0.000
L1.Steiermark 0.045380 0.053755 0.844 0.399
L1.Tirol 0.104749 0.043540 2.406 0.016
L1.Vorarlberg -0.061207 0.038386 -1.595 0.111
L1.Wien 0.033201 0.070347 0.472 0.637
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.040693 0.126710 0.321 0.748
L1.Burgenland -0.030496 0.081972 -0.372 0.710
L1.Kärnten 0.040197 0.043118 0.932 0.351
L1.Niederösterreich -0.182328 0.170570 -1.069 0.285
L1.Oberösterreich 0.444815 0.168730 2.636 0.008
L1.Salzburg 0.284932 0.087222 3.267 0.001
L1.Steiermark 0.108368 0.114266 0.948 0.343
L1.Tirol 0.315011 0.092551 3.404 0.001
L1.Vorarlberg 0.023447 0.081595 0.287 0.774
L1.Wien -0.036965 0.149534 -0.247 0.805
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186661 0.030607 6.099 0.000
L1.Burgenland 0.088922 0.019800 4.491 0.000
L1.Kärnten -0.007935 0.010415 -0.762 0.446
L1.Niederösterreich 0.257536 0.041201 6.251 0.000
L1.Oberösterreich 0.152856 0.040757 3.750 0.000
L1.Salzburg 0.043616 0.021068 2.070 0.038
L1.Steiermark 0.023341 0.027601 0.846 0.398
L1.Tirol 0.085405 0.022356 3.820 0.000
L1.Vorarlberg 0.053637 0.019709 2.721 0.006
L1.Wien 0.117099 0.036120 3.242 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109716 0.030706 3.573 0.000
L1.Burgenland 0.044759 0.019865 2.253 0.024
L1.Kärnten -0.014266 0.010449 -1.365 0.172
L1.Niederösterreich 0.183000 0.041335 4.427 0.000
L1.Oberösterreich 0.325643 0.040889 7.964 0.000
L1.Salzburg 0.102038 0.021137 4.827 0.000
L1.Steiermark 0.109229 0.027690 3.945 0.000
L1.Tirol 0.097853 0.022428 4.363 0.000
L1.Vorarlberg 0.061954 0.019773 3.133 0.002
L1.Wien -0.020915 0.036237 -0.577 0.564
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118604 0.056993 2.081 0.037
L1.Burgenland -0.045470 0.036870 -1.233 0.217
L1.Kärnten -0.046153 0.019394 -2.380 0.017
L1.Niederösterreich 0.142172 0.076720 1.853 0.064
L1.Oberösterreich 0.160188 0.075893 2.111 0.035
L1.Salzburg 0.281966 0.039231 7.187 0.000
L1.Steiermark 0.053716 0.051395 1.045 0.296
L1.Tirol 0.165077 0.041628 3.966 0.000
L1.Vorarlberg 0.096151 0.036700 2.620 0.009
L1.Wien 0.076068 0.067258 1.131 0.258
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058803 0.045031 1.306 0.192
L1.Burgenland 0.031266 0.029131 1.073 0.283
L1.Kärnten 0.051434 0.015323 3.357 0.001
L1.Niederösterreich 0.203957 0.060618 3.365 0.001
L1.Oberösterreich 0.316724 0.059964 5.282 0.000
L1.Salzburg 0.041467 0.030997 1.338 0.181
L1.Steiermark 0.008932 0.040608 0.220 0.826
L1.Tirol 0.132516 0.032891 4.029 0.000
L1.Vorarlberg 0.067689 0.028998 2.334 0.020
L1.Wien 0.087839 0.053142 1.653 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168797 0.053829 3.136 0.002
L1.Burgenland 0.007306 0.034823 0.210 0.834
L1.Kärnten -0.065011 0.018317 -3.549 0.000
L1.Niederösterreich -0.089563 0.072461 -1.236 0.216
L1.Oberösterreich 0.200548 0.071680 2.798 0.005
L1.Salzburg 0.054758 0.037054 1.478 0.139
L1.Steiermark 0.239503 0.048542 4.934 0.000
L1.Tirol 0.502605 0.039317 12.783 0.000
L1.Vorarlberg 0.060301 0.034663 1.740 0.082
L1.Wien -0.077112 0.063525 -1.214 0.225
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150823 0.059911 2.517 0.012
L1.Burgenland 0.002627 0.038758 0.068 0.946
L1.Kärnten 0.060661 0.020387 2.975 0.003
L1.Niederösterreich 0.186148 0.080649 2.308 0.021
L1.Oberösterreich -0.061007 0.079779 -0.765 0.444
L1.Salzburg 0.206861 0.041241 5.016 0.000
L1.Steiermark 0.133448 0.054027 2.470 0.014
L1.Tirol 0.070695 0.043760 1.616 0.106
L1.Vorarlberg 0.143425 0.038580 3.718 0.000
L1.Wien 0.108073 0.070703 1.529 0.126
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375122 0.035349 10.612 0.000
L1.Burgenland -0.001489 0.022868 -0.065 0.948
L1.Kärnten -0.022101 0.012029 -1.837 0.066
L1.Niederösterreich 0.215141 0.047585 4.521 0.000
L1.Oberösterreich 0.224355 0.047072 4.766 0.000
L1.Salzburg 0.039996 0.024333 1.644 0.100
L1.Steiermark -0.015762 0.031878 -0.494 0.621
L1.Tirol 0.096408 0.025820 3.734 0.000
L1.Vorarlberg 0.055642 0.022763 2.444 0.015
L1.Wien 0.034456 0.041717 0.826 0.409
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038143 0.120829 0.177804 0.144351 0.104401 0.087326 0.040202 0.213850
Kärnten 0.038143 1.000000 -0.018734 0.135642 0.052918 0.091530 0.441757 -0.059448 0.094457
Niederösterreich 0.120829 -0.018734 1.000000 0.325127 0.132838 0.284444 0.078887 0.163645 0.303449
Oberösterreich 0.177804 0.135642 0.325127 1.000000 0.221625 0.312424 0.171665 0.152192 0.255386
Salzburg 0.144351 0.052918 0.132838 0.221625 1.000000 0.131893 0.101010 0.116946 0.132562
Steiermark 0.104401 0.091530 0.284444 0.312424 0.131893 1.000000 0.143406 0.120941 0.056118
Tirol 0.087326 0.441757 0.078887 0.171665 0.101010 0.143406 1.000000 0.074559 0.152118
Vorarlberg 0.040202 -0.059448 0.163645 0.152192 0.116946 0.120941 0.074559 1.000000 0.010467
Wien 0.213850 0.094457 0.303449 0.255386 0.132562 0.056118 0.152118 0.010467 1.000000